package ysq.xyg.sys.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.sys.model.po.SysDictContent;
import ysq.xyg.sys.model.vo.SysDictContentVo;
import ysq.xyg.sys.service.SysDictContentService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 系统部分-字典controller层
 *
 * @author shengQiang yu
 * @date 2018-03-18 15:42
 */
@RestController
public class SysDictContentController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(SysDictContentController.class);
    @Resource
    private SysDictContentService sysDictContentService;

    private SysDictContent sysDictContent;

    /**
     * 跳转分页页面
     *
     * @param dictType 字典类型
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @RequestMapping(value = "/sysDictContent/getPage",method = RequestMethod.GET)
    public ModelAndView getPage(String dictType){
        ModelAndView view = new ModelAndView("/sys/sysDictContentList");
        view.addObject("dictType", dictType);
        return view;
    }
    /**
     * 分页查询
     *
     * @param sysDictContentVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */

    @BaseLog(module = "系统模块",className = "字典管理",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/sysDictContent/page",method = RequestMethod.POST)
    public ReturnEntity page(SysDictContentVo sysDictContentVo, int pageSize, int pageNum){
        ReturnEntity returnResult = sysDictContentService.page(sysDictContentVo,pageSize,pageNum);
        return returnResult;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @param dictType 字典类型
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @RequestMapping(value = "/sysDictContent/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id,String dictType){
        ModelAndView view = new ModelAndView("/sys/sysDictContentUpdateOrSave");
        view.addObject("dictType", dictType);
        if(StrUtil.isNotEmpty(id)){
            sysDictContent = sysDictContentService.selectByPrimaryKey(id);
        }else{
            sysDictContent=new SysDictContent();
            sysDictContent.setDictType(dictType);
        }
        view.addObject("sysDictContent", sysDictContent);
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @BaseLog(module = "系统模块",className = "字典内容管理",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/sysDictContent/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return sysDictContentService.delete(id,acceptCurrentUser(request));
    }
    /**
     * 根据dictType获取集合
     *
     * @param dictTypes dictType集合,多个以“，”隔开
     * @return ReturnEntity 对象
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @RequestMapping(value = "/sysDictContent/listByDictTypes")
    public ReturnEntity listByDictTypes(String dictTypes){
        return sysDictContentService.listByDictTypes(dictTypes);
    }
    /**
     * 添加或修改
     *
     * @param sysDictContentVo Vo对象
     * @author shengQiang yu
     * @date 2018-03-18 16:26
     */
    @BaseLog(module = "系统模块",className = "字典内容管理",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/sysDictContent/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,SysDictContentVo sysDictContentVo){
        return sysDictContentService.addOrUpdate(sysDictContentVo,acceptCurrentUser(request));
    }
}